import { Radio, RadioGroupProps } from 'antd';
import { FC } from 'react';
import FormItem, { FormItemProps } from '@/components/form-item';
import { isObject } from 'lodash';

const { Group, Button } = Radio;

interface RadioButtonGroupItemProps extends FormItemProps {
  radioGroupProps?: Omit<RadioGroupProps, 'options'>;
  options: RadioGroupProps['options'];
}

const RadioButtonGroupItem: FC<RadioButtonGroupItemProps> = ({
  radioGroupProps,
  options,
  ...restProps
}) => {
  return (
    <FormItem {...restProps}>
      <Group {...radioGroupProps}>
        {options?.map((item) => {
          if (isObject(item)) {
            const { disabled, label, value } = item;
            return (
              <Button disabled={disabled} value={value}>
                {label}
              </Button>
            );
          }
          return <Button value={item}>{item}</Button>;
        })}
      </Group>
    </FormItem>
  );
};

export default RadioButtonGroupItem;
